package bairui.international.console.web.controller.product.category;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;
import com.querydsl.core.BooleanBuilder;

import bairui.international.common.config.Config_Setup;
import bairui.international.model.domain.jpa.QTB_ProductCategory;
import bairui.international.service.Service_ProductCategory;

/**
 *
 * 列表
 *
 * @generated
 * 
 * @see STest_C_Product_Category_Tree_Tree 测试
 *
 */
@Controller
public class C_Product_Category_Tree_Tree
 extends SC_Product_Category_Tree_Tree  
{
	
	@Autowired private Service_ProductCategory service_ProductCategory;
	
	private static final QTB_ProductCategory QRoot = QTB_ProductCategory.tB_ProductCategory;
	
	/**
	 * 分类树
	 */
	@Action(Tree.class)
	@GetMapping(value=Tree.RequestMappingValue, consumes=MediaType.APPLICATION_JSON_VALUE)
	public @FomatOutput @ResponseBody Object tree(
		HttpServletRequest request, 
		@PathVariable(name=Tree.PathVariableName.ParentId) Long parentId
	) throws Exception {
		if(null != parentId){
			return Tree.Output.output(
					service_ProductCategory.findSubProductCategory(parentId, QRoot.orderValue.desc())
				);
		}else{
			BooleanBuilder query = new BooleanBuilder();
				query.and(
						QRoot.name.ne(Config_Setup.Advance)
						.and(QRoot.name.ne(Config_Setup.Barter))
						.and(QRoot.name.ne(Config_Setup.Delicate))
						.and(QRoot.name.ne(Config_Setup.Wrap))
					);
			return Tree.Output.output(
					service_ProductCategory.findRootProductCategory(query, QRoot.orderValue.desc())
				);
		}
	}

}
